package com.sjx.jnistudy;

import android.os.Bundle;
import android.os.Process;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity1 extends AppCompatActivity {

    int freq[] = {400, 450, 500, 550, 600, 650, 700, 750, 800, 850,
            900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350,
            1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1850,
            1900, 1950};


    int amplitude[] = {0, 60, 0, 0, 80, 0, 0, 60, 50, 20,
            20, 30, 0, 0, 0, 50, 0, 80, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0};
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        byte array[] = {'A', 'B', 'C', 'D', 'E'};
        byte[] resutl = CalcUtils.getByteArray(array);
        for (int i = 0; i < array.length; i++) {
            Log.d("TAG", "ARRAY : " + array[i] + "->" + resutl[i]);
        }
        byte result[] = new byte[800];
        for (int i = 0; i< 30; i++){
            Log.e("起始时间", System.currentTimeMillis()+"");
            CalcUtils.sinWave(freq, amplitude, 8000, 100, 100, result);
            Log.e("终止时间", System.currentTimeMillis()+"");
            Log.e("TAG", result.length + "");
        }
        new MyThread().start();
    }

    static {
        System.loadLibrary("calc-utils");
    }

    public class MyThread extends Thread {

        public MyThread(){
            Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
        }

        @Override
        public void run() {
            super.run();
            byte result[] = new byte[800];
            for (int i = 0; i< 30; i++){
                Log.e("子线程-起始时间", System.currentTimeMillis()+"");
                CalcUtils.sinWave(freq, amplitude, 8000, 100, 100, result);
                Log.e("子线程-终止时间", System.currentTimeMillis()+"");
                Log.e("子线程-TAG", result.length + "");
            }
        }
    }
}
